# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=headers
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
replaces="${MINGW_PACKAGE_PREFIX}-${_realname}-svn"
pkgdesc="MinGW-w64 headers for Windows"
_ver_base=4.0.0
pkgver=4.0.0.4063.a24fb0f
pkgrel=1
arch=('any')
url="http://mingw-w64.sourceforge.net"
license=('custom')
groups=("${MINGW_PACKAGE_PREFIX}-toolchain" "${MINGW_PACKAGE_PREFIX}")
makedepends=('git')
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
options=('!strip' '!libtool' '!emptydirs')
source=("${_realname}"::"git://git.code.sf.net/p/mingw-w64/mingw-w64")
md5sums=('SKIP')

pkgver() {
  cd "$srcdir/$_realname"
  printf "%s.%s.%s" "$_ver_base" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd ${srcdir}/${_realname}
}

build() {
    msg "Configuring ${MINGW_CHOST} headers"
    mkdir -p ${srcdir}/headers-${MINGW_CHOST} && cd ${srcdir}/headers-${MINGW_CHOST}
    ${srcdir}/${_realname}/mingw-w64-headers/configure \
      --build=${MINGW_CHOST} \
      --host=${MINGW_CHOST} \
      --target=${MINGW_CHOST} \
      --prefix=${MINGW_PREFIX}/${MINGW_CHOST} \
      --enable-sdk=all \
      --enable-secure-api
}

package() {
  msg "Installing ${MINGW_CHOST} headers"
  cd ${srcdir}/headers-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install

  rm ${pkgdir}${MINGW_PREFIX}/${MINGW_CHOST}/include/pthread_signal.h
  rm ${pkgdir}${MINGW_PREFIX}/${MINGW_CHOST}/include/pthread_time.h
  rm ${pkgdir}${MINGW_PREFIX}/${MINGW_CHOST}/include/pthread_unistd.h

  msg "Installing MinGW-w64 licenses"
  install -Dm644 ${srcdir}/${_realname}/mingw-w64-headers/ddk/readme.txt ${pkgdir}${MINGW_PREFIX}/share/licenses/${pkgname}/ddk-readme.txt
  install -Dm644 ${srcdir}/${_realname}/mingw-w64-headers/direct-x/COPYING.LIB ${pkgdir}${MINGW_PREFIX}/share/licenses/${pkgname}/direct-x-COPYING.LIB
  install -Dm644 ${srcdir}/${_realname}/mingw-w64-headers/direct-x/readme.txt ${pkgdir}${MINGW_PREFIX}/share/licenses/${pkgname}/direct-x-readme.txt	
}
